{{include file ="admin/header.tpl"}}
{{include file ="admin/navibar.tpl"}}
{{include file ="admin/sidebar.tpl"}}


<div class="content">

    <div class="header">
        <div class="stats">
            <p class="stat">
                <!--span class="number"></span-->
            </p>
        </div>

        <h3 class="page-title">用户积分审批申请</h3>
    </div>


    <div class="container-fluid">

        <div class="block">

            <table id="grid"
                   data-options="url:'admin/pointsApproval/getpointsApply',fitColumns:true,singleSelect:true"
                   class="easyui-datagrid" toolbar="#toolbar"
                   style="width: auto; height: 350px" iconCls="icon-save"
                   pagination="true">
            <thead>
            <tr>
                <th data-options="field:'userid',checkbox:true,width:100"></th>
                <th data-options="field:'username',width:100">用户名</th>
                <th data-options="field:'points',width:100">积分</th>
                <th data-options="field:'state',width:100,formatter: convertState">审核状态</th>
                <th data-options="field:'apply_content',width:100">申请内容</th>
                <th data-options="field:'apply_time',width:100">审批时间</th>
                <th data-options="field:'reply_userid',width:100">审批人id</th>
                <th data-options="field:'reply_username',width:100">审批人</th>
                <th data-options="field:'reply_time',width:100">回复时间</th>
            </tr>
            </thead>
            </table>
            <!--- START 分页模板 --->
            <div id="toolbar">
                <a  class="easyui-linkbutton" href="javascript:void(0)"  iconCls="icons-add"
                    plain="true" onclick="approval()">审核用户信息</a>
            </div>

            <!--- END --->
        </div>


    </div>

    <div id="editWin" class="modal hide fade">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"
                    aria-hidden="true">&times;</button>
            <h5>用户积分审核</h5>
        </div>
        <div class="modal-body">
            <form id="form" method="post" class="form-horizontal">

                <div class="control-group" hidden="true">
                    <input type="text" name="id" hidden="true">
                </div>

                <<div class="control-group" hidden="true">
                    <input type="text" name="userid" hidden="true">
                </div>

                <div class="control-group">
                    <label class="control-label" for="Text input">申请内容:</label>
                    <div class="controls">
                        <textarea rows="2" name="apply_content"></textarea>
                    </div>
                </div>

                <div class="control-group">
                    <label class="control-label" for="Text input">审核状态:</label>
                    <div class="controls">
                        <select id="state" name="state">
                            <option value="0">未通过</option>
                            <option value="1">通过</option>
                            <option value="2">审核中</option>
                        </select>
                    </div>
                </div>

                <div class="control-group">
                    <label class="control-label" for="Text input">积分数:</label>
                    <div class="controls">
                        <input id="points" type="text" name="points">
                    </div>
                </div>


            </form>
        </div>
        <div class="modal-footer" id="div_view">
            <button type="button" style="width: 100px;" class="btn btn-primary"
                    onclick="submit()">提交</button>
            <button type="button" onclick="winhide()" style="width: 100px;"
                    class="btn">取消</button>

        </div>
    </div>

    <script>
        $(function(){
            $("#state").on('change',function(){
                var state = $(this).val();
                if(state==1){
                    //审核通过，
                    $("#points").removeAttr("readonly");
                }else{
                    $("#points").attr("readonly","readonly");
                }
            });
        })

        function approval(){
            var selectedData = getSelectedData();
            if(selectedData == null || selectedData.length == 0 ){
                $.messager.alert('错误','请选择要修改的记录!');
                return;
            }
            $("#form").form('clear');
            modelshow();
            $("#form").form('load',selectedData[0]);


            //设置审批状态
            var state = selectedData[0].state;
            if(!state){
                state = 2;
            }
            if(state==1){
                $("#points").removeAttr("readonly");
            }else{
                $("#points").attr("readonly","readonly");
            }

            $("#state").val(state);
        }

        function winhide(){
            modelhide();
        }

        function modelshow(){
            $('#editWin').modal('show');
        }
        function modelhide(){
            $('#editWin').modal('hide');
        }

        function getSelectedData(){
            var select  = $("#grid").datagrid('getSelections');
            if(select == null || select.length == 0 ){
                return null;
            }
            return select;
        }

        function submit(){
            if(!$('#form').form('validate')){
                return;
            }

            $.ajax({
                type: 'POST',
                url: '{{$smarty.const.WEBSITE_URL}}admin/pointsApproval/approval',
                data: $('#form').serialize(),
                success: function(data){
                    modelhide();
                    $('#grid').datagrid('reload');
                }

            });

        }

        function convertState(value,rowData){
            if(value=='0'){
                return '未通过';
            }else if(value=='1'){
                return "通过";
            }else {
                return '审核中';
            }

        }

    </script>

    <!--- END 以下内容不需更改，请保证该TPL页内的标签匹配即可 --->
{{include file="admin/footer.tpl" }}